﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetMemberScoreRankList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            MemberScoreRankOutParam result = new MemberScoreRankOutParam();
            MemberScoreRankInParam param = new MemberScoreRankInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as MemberScoreRankInParam;
                if (param.page_no <= 0 || param.page_count <= 0 || 
                    (param.type != "1" && param.type != "2") || 
                    (param.type == "2" && string.IsNullOrEmpty(param.branch_id)))
                {
                    result.code = "0";
                    result.desc = "请求参数不正确";

                    isFlag = false;
                }

                if(isFlag)
                {
                    DataSet ds = InterfaceHelper.GetMemberScoreRankList(param.type, param.branch_id, param.order_type, param.page_no, param.page_count);
                    if (ds != null && ds.Tables.Count == 2)
                    {
                        MemberScoreRank itemTemp;
                        //result.data.total_pages = Convert.ToInt32(ds.Tables[0].Rows[0][0]) / param.page_count + 1;
                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[0].Rows[0][0]), param.page_count);

                        foreach (DataRow dr in ds.Tables[1].Rows)
                        {
                            itemTemp = new MemberScoreRank();
                            itemTemp.party_id = dr["party_id"].ToString();
                            itemTemp.party_name = dr["party_name"].ToString();
                            itemTemp.rank_num = dr["rank_num"].ToString();
                            itemTemp.total_int = dr["total_int"].ToString();

                            result.data.list.Add(itemTemp);
                        }
                    } 
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetMemberScoreRankList", SerializeHelper.JsonSerializer<MemberScoreRankInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<MemberScoreRankInParam, MemberScoreRankOutParam>();
            else
                SafeProcessRequest<MemberScoreRankInParam, MemberScoreRankOutParam>();
        }
    }

    #region 请求参数
    public class MemberScoreRankInParam
    {
        /// <summary>
        /// 必填，	类别 1：个人积分排名，2：所在支部排名
        /// </summary>
        public string type
        { get; set; }

        /// <summary>
        /// 排序方式(默认升序) 1：升序，2：降序
        /// </summary>
        public string order_type
        { get; set; }

        /// <summary>
        /// 支部ID 如果是支部排名，则提供支部ID
        /// </summary>
        public string branch_id
        { get; set; }

        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class MemberScoreRankOutParam
    {
        public MemberScoreRankOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new MemberScoreRankList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 个人积分排名列表
        /// </summary>
        public MemberScoreRankList data
        { get; set; }
    }

    public class MemberScoreRankList
    {
        public MemberScoreRankList()
        {
            total_pages = 0;
            list = new List<MemberScoreRank>();
        }

        public List<MemberScoreRank> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }
     
    /// <summary>
    /// 个人积分排名列表
    /// </summary>
    public class MemberScoreRank
    {
        /// <summary>
        ///	党员ID
        /// </summary>
        public string party_id
        { get; set; }

        /// <summary>
        ///	党员姓名
        /// </summary>
        public string party_name
        { get; set; }

        /// <summary>
        ///	总积分
        /// </summary>
        public string total_int
        { get; set; }

        /// <summary>
        ///	排名位置
        /// </summary>
        public string rank_num
        { get; set; } 
    }
    #endregion 
}